package com.xy.modular.haha.controller;
import com.xy.framework.mreturn.MReturnObject;
import com.xy.modular.haha.model.HahaHaha;
import com.xy.modular.haha.service.IHahaHahaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * Created by BCK on 2019/08/21.
 */
@Controller
@RequestMapping("/hahaHaha/")
public class HahaHahaController {

    @Autowired
    IHahaHahaService hahaHahaService;

    @RequestMapping("add")
    @ResponseBody
    public String add(HahaHaha hahaHaha) {
        hahaHahaService.save(hahaHaha);
        return "";
    }

    @RequestMapping("delete")
    @ResponseBody
    public String delete(@RequestParam String id) {
	    hahaHahaService.deleteById(id);
	    return "";
    }

    @RequestMapping("update")
    @ResponseBody
    public String update(HahaHaha hahaHaha) {
	    hahaHahaService.update(hahaHaha);
	    return "";
    }

    @RequestMapping("detail")
    @ResponseBody
    public String detail(@RequestParam String id) {
        HahaHaha hahaHaha = hahaHahaService.getById(id);
        return hahaHaha.toString();
    }

    @RequestMapping("list")
    @ResponseBody
    public MReturnObject list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        return new MReturnObject(MReturnObject.SUCCESS, hahaHahaService.findAll());
    }
}
